VB 如何随机读取1-10数字`

来源:百度知道 编辑:UC知道 时间:2024/05/22 10:13:21
比如~:
随机读取后为 6543987210
要十个数不重复出现~~

Private Sub Command1_Click()
Dim a(10) As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To 10
Randomize
l:
a(i) = Int(10 * Rnd)
For j = 1 To i - 1
If a(j) = a(i) Then GoTo l
Next j
Next i
Print a(1) & " " & a(2) & " " & a(3) & " " & a(4) & " " & a(5) & " " & a(6) & " " & a(7) & " " & a(8) & " " & a(9) & " " & a(10)
End Sub

好了,只需要一个按钮控件
试一试吧,呵呵

<html>
<head>
<script language="vbscript">
dim arr(9)
dim i,j,k,m
for i = 0 to 9
arr(i) = i
next
Randomize()
for m = 1 to 100
for i = 0 to 9
j=rnd()*9
k = arr(j)
arr(j) = arr(0)
arr(0) = k
next

for i = 0 to 9
document.Write(arr(i))
next
document.Write("<br>")
next
</script&g